<template>
  <el-container>
    <el-main>
      <el-row class="houselist" v-for="item in houseinfo" :key="item.id">
        <el-col :span="24">
          <div
            class="block"
            @click="$router.push('/myrentdetail?id=' + item.id)"
          >
            <el-image
              v-if="item.firstImage"
              style="width: 200px; height: 137px"
              :src="item.firstImage"
              :key="item.id"
              :lazy="true"
            ></el-image>

            <div class="info">
              <p class="title">{{ item.title }}</p>
              <p class="detail">
                {{ item.bedroom }}室{{ item.living }}厅|{{ item.area }}平米|{{
                  item.floor
                }}层（共{{ item.allfloor }}层） {{ item.mastername }}
              </p>
              <p class="site">{{ item.houseSite }}</p>
            </div>

            <div class="money">
              <p>
                <strong>{{ item.money }}</strong>
                元/月
              </p>
            </div>
          </div>
        </el-col>
      </el-row>
    </el-main>
  </el-container>
</template>


<script>
import request from "@/utils/request";
export default {
  components: {},
  data() {
    return {
      id: "",
      houseinfo: [],
    };
  },
  async created() {
    const id = this.$route.query.id;
    const res = await request.get(`/house/list/${id}/rent`);
    if (res.code === 200) {
      this.houseinfo = res.data;
      for (let i = 0; i < this.houseinfo.length; i++) {
        const imgRes = await request.get(
          `/house/firstimg/${this.houseinfo[i].houseAccount}`
        );
        const userRes = await request.get(`/user/${this.houseinfo[i].ownerId}`);
        if (imgRes.code === 200) {
          this.$set(this.houseinfo[i], "firstImage", imgRes.data);
        }
        if (userRes.code === 200) {
          console.log(userRes.data);
          this.$set(this.houseinfo[i], "mastername", userRes.data.nikeName);
        }
      }
    } else {
      this.$notify.error(res.msg);
    }
  },
};
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  /* background-color: #e9eef3; */
  color: #333;
  text-align: center;
  /* line-height: 160px; */
  overflow: hidden;
  margin-top: -20px !important;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.search_area {
  width: 100%;
  min-width: 1150px;
  height: 150px;
  padding: 25px 0;
  background: #f5f5f6;
  box-sizing: border-box;
  z-index: 5;
  position: relative;
}
.belike_nav {
  width: 1150px;
  height: 30px;
  margin: 0 auto 30px 300px;
  position: absolute;
}
.belike_nav .belike_nav_tab,
.belike_nav .belike_nav_tab li {
  display: inline-block;
  vertical-align: bottom;
  position: relative;
}
.green_logo {
  position: absolute;
  color: #007e63;
  margin-left: 37px;
}
.green_logo i {
  font-size: 50px;
}

.belike_nav .belike_nav_tab ul {
  margin-left: 73px;
}
.belike_nav .belike_nav_tab li {
  line-height: 25px;
  font-size: 16px;
  margin-right: 30px;
  position: relative;
  font-weight: 700;
  list-style: none;
}

.search {
  margin-top: 65px;
  margin-bottom: 24px;
  position: absolute;
  width: 1150px;
  margin-left: 300px;
}
.search .search__wrap {
  display: inline-block;
  width: 710px;
  line-height: 46px;
  font-size: 14px;
  border-radius: 2px;
}
.el-input {
  width: 400px !important;
}
/* 房源 */
.houselist {
  /* margin-bottom: 20px; */
  background-color: #fff;
  border-bottom: 1px dashed #e6e6e6;
  cursor: pointer;
  /* width: 900px; */
  width: 800px;
  height: 184px;
  padding: 20px;
  position: relative;
  /* border-top: 1px dashed black; */
  margin-left: -430px;
  left: 50%;
}
.el-col {
  border-radius: 4px;
}
/* .bg-purple-dark {
  background: #99a9bf;
} */
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
/* .grid-content {
  border-radius: 4px;
  min-height: 36px;
} */

.block {
  position: relative;
}
.el-image {
  position: absolute;
  display: inline-block;
  overflow: hidden;
  margin-left: -50%;
  margin-top: 4px;
  /* margin-top: -9px; */
}
.info {
  position: absolute;
  color: #797979;
  /* float: left; */
  left: 30%;
  font-size: 14px;
  overflow: hidden;
  /* padding-left: 20px; */
  width: 460px;
  text-align: left;
  font-family: Microsoft YaHei, 微软雅黑, Hiragino Sans GB, tahoma, arial,
    simhei;
}
.title {
  color: #333;
  font-size: 20px;
  font-weight: 700;
  font-family: "Microsoft YaHei";
}
.detail {
  font-size: 15px;
  font-weight: 700;
  color: #333;
}
.site {
  color: #666;
  font-size: 14px;
}
.money {
  position: absolute;
  float: right;
  width: 112px;
  right: 5%;
  margin-top: 5%;
  color: #eb5f00;
  font-size: 20px;
  font-weight: 700;
}
</style>